// 
//  Test_StringEncryptionHelper.cs
//  
//  Author:
//       Ray Shaw <demogodyou@gmail.com>
// 
//  Copyright (c) 2009 Ray Shaw(xiaolei)
// 
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
// 
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// 
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行时版本:2.0.50727.3053
//
//     对此文件的更改可能会导致不正确的行为，并且如果
//     重新生成代码，这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using SharpNote.Core.Security;


namespace Test
{


	public class Test_StringEncryptionHelper : ITestCase
	{

		public Test_StringEncryptionHelper ()
		{

		}

		public bool Test ()
		{
			string plainText = "this is a test for string encryption.";
			string cipherText = string.Empty;
			string password = "test123";
			
			byte[] plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
			byte[] cipherTextBytes = null;

			/*
			for (int i = 0; i < 10; i++) {
				Console.WriteLine(string.Format("<Count {0}>-------------------------------------", i + 1));
				password = Guid.NewGuid().ToString();
				Console.WriteLine (string.Format ("  Plain text: {0}  password: {1}.", plainText, password));

				bool encryptOk = StringEncryptionHelper.EncryptString (plainText, password, out cipherText);
				Console.WriteLine (string.Format ("  Encrypt ok: {0}, cipher text: {1}.", encryptOk, cipherText));

				bool decryptOk = StringEncryptionHelper.DecryptString (cipherText, password, out plainText);
				Console.WriteLine (string.Format ("  Decrypt ok: {0}, plain text: {1}.", decryptOk, plainText));

				if (!encryptOk || !decryptOk) {
					return false;
				}
				Console.WriteLine("----------------------------------------------");
			}
			*/
			
			for (int i = 0; i < 10; i++) {
				Console.WriteLine(string.Format("<Count {0}>-------------------------------------", i + 1));
				password = Guid.NewGuid().ToString();
				Console.WriteLine (string.Format ("  Plain text: {0}  password: {1}.", plainText, password));

				bool encryptOk = StringEncryptionHelper.EncryptString (plainText, password, out cipherTextBytes);
				Console.WriteLine (string.Format ("  Encrypt ok: {0}, cipher text: {1}.", encryptOk, 
				                                  Convert.ToBase64String(cipherTextBytes)));

				bool decryptOk = StringEncryptionHelper.DecryptString (cipherTextBytes, password, out plainText);
				Console.WriteLine (string.Format ("  Decrypt ok: {0}, plain text: {1}.", decryptOk, plainText));

				if (!encryptOk || !decryptOk) {
					return false;
				}
				Console.WriteLine("----------------------------------------------");
			}

			return true;
		}
	}
}
